<?php

/**
* @current thread.php
* @author   LiuYang <liu_yang@haibao.com>
* @date 2016年4月27日 下午5:29:43
*/

namespace haibao\user\data;

class Thread extends \haibao\user\data\BaseMysql {
    
    public function __construct() {
        parent::__construct ( '\haibao\user\model\data\Thread' );
        $this->setConfig( \haibao\classlibrary\www\Config::CLASSLIBRARY_CONFIG_MYSQL_HAIBAO_DZ3 );
    }
    
    public function getThreadPorperty($userId,$isMySelf){
        $sql='SELECT b.authorid, SUM(a.favtimes) AS FavTimes, SUM(a.replies) AS Replies, SUM(a.views) AS Views, SUM(c.addviews) AS AddViews
                FROM `hb_forum_thread` as a
                LEFT JOIN `hb_forum_post` AS b ON b.`tid` = a.`tid`
                LEFT JOIN `hb_forum_threadaddviews` as c ON b.`tid` = c.`tid`
                WHERE b.`authorid` = %s AND b.`first` = 1';
        if(!$isMySelf){
            $sql .= ' AND b.`invisible` = '.\haibao\user\model\data\Post::INVISIBLE_CHECKED_SUCCESS;
        }
        $result = $this->query($sql,array($userId));
        
        $temp = array();
        
        while ($row = $result->fetch_assoc()){
            $temp = $row;
        }
        
        return $temp;
    }
}
